package com.tenglong.teacher.ui.homework;

import android.content.Context;
import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;


import com.cuotibao.zhuoxiao.basics.utils.Utils;

import static com.tenglong.teacher.ui.homework.HomeWorkDetailAdapter.GRIDSPAN_IMAGE;

/**
 * Created by wim on 4/14/16.
 */
public class GridMarginDecoration extends RecyclerView.ItemDecoration {


    private Context mContext;
    private int screenWidth;
    private int imageSpace;
    public static final int TITLE_MARGIN=35;
    public static final int IMAGE_WIDTH=85;
    public static final int COMMON=-1;
    public static final int IMAGE_START=1;
    public static final int IMAGE_MIDDLE=2;
    public static final int IMAGE_FINAL=3;
    private HomeWorkDetailAdapter mAdapter;

    public GridMarginDecoration(Context context, HomeWorkDetailAdapter adapter) {

        mAdapter=adapter;
        mContext=context;
        calculateImageSpace(context);


    }
    private void calculateImageSpace(Context context){
        screenWidth= Utils.getScreenMetrics(context).x;
        int imgTotalW=screenWidth-Utils.dip2px(mContext,TITLE_MARGIN)-Utils.dip2px(mContext,11)*2;
        imageSpace=(imgTotalW-Utils.dip2px(mContext,IMAGE_WIDTH)*GRIDSPAN_IMAGE)/3;

    }
    @Override
    public void getItemOffsets(
            Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        int pos = parent.getChildAdapterPosition(view);
//        int type=getDecorationType(pos);
        outRect.set(imageSpace/6, 0, 0, 0);
//        switch (type){
//            case IMAGE_START:
//                outRect.set(Utils.dip2px(mContext,TITLE_MARGIN), 0, 0, 0);
//                break;
//            case IMAGE_MIDDLE:
//                outRect.set(imageSpace, 0, 0, 0);
//                break;
//            case IMAGE_FINAL:
//                //outRect.set(imageSpace/2, 0, imageSpace/2, 0);
//                outRect.set(imageSpace/3, 0, 0, 0);
//                break;
//            default:
//                outRect.set(0, 0, 0, 0);
//
//        }



    }

//    private int getDecorationType(int pos){
//        int type= mAdapter.mDecorationType.get(pos);
//
//        if(type==0){
//            return IMAGE_START;
//        }else if(type<(GRIDSPAN_IMAGE-1)&&type>0){
//            return IMAGE_MIDDLE;
//        }else if(type==(GRIDSPAN_IMAGE-1)){
//            return IMAGE_FINAL;
//        }else{
//            return COMMON;
//        }
//
//
//    }
}
